package com.zhike.b2b.html.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.zhike.b2b.base.BaseService;
import com.zhike.b2b.html.ILinkService;
import com.zhike.b2b.model.LinkVo;

@Service
public class LinkService extends BaseService implements ILinkService {
     
	 /* (non-Javadoc)
	 * @see com.zhike.b2b.html.impl.ILinkService#queryLinks(java.lang.String, java.lang.String)
	 */
	 public List<LinkVo> queryLinks(String custId, String rownum)
	 {
		return jt.query(getSqlstr(custId,rownum), new RowMapper<LinkVo>()
		 {
			public LinkVo mapRow(ResultSet rs, int num) throws SQLException {
				LinkVo lv = new LinkVo();
				lv.setName(rs.getString("link_name"));
				lv.setUrl(rs.getString("link_addr"));
				return lv;
			}
		});
	 }
	
	 private  String getSqlstr(String custId, String rownum)
	  {
	    StringBuffer sql = new StringBuffer("select link_name,link_addr from links where display=1 and checked=1 and remove_tag=1 ");
	    if (custId.equals(""))
	    	custId = "100000000000000";
	    sql.append("and cust_id='" + custId + "'");
	   
	    if (!rownum.equals(""))
	      sql.append(" limit 0," + rownum);
	    logger.debug("sbstr=" + sql.toString());
	    return sql.toString();
	  }
}
